package org.hot100_2;

public class leetcode53 {
    public int maxSubArray(int [] nums){

        int n = nums.length;
        int [] dp = new int[n];
        dp[0]=nums[0];
        int MaxSum = nums[0];
        for (int i = 1; i <n; i++) {
            if (dp[i-1]>0){
                dp[i]=dp[i-1]+nums[i];
            }else {
                dp[i]=nums[i];
            }

            MaxSum=Math.max(MaxSum,dp[i]);
        }

        return MaxSum;
    }
}
